<@>layout("/common/default.html"){
<script type="text/javascript" src="${ctxPath}/static/ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="${ctxPath}/static/ueditor/ueditor.all.js"></script>
<div class="x-body">
    <form class="layui-form" id="excelTemplate-date">
        <div class="layui-form-item">
            <label class="layui-form-label">名称：</label>
            <div class="layui-input-block">
                <input type="text" lay-verify="required" class="layui-input" id="name" name="name" value="${excelTemplate.name}" style="width: 95%">
            </div>
        </div>
        <div class="layui-form-item">
            <div style="width: 100%">
                <script id="editor" type="text/plain" style="width:1024px;height:500px;"></script>
            </div>
        </div>
        <input type="hidden" name="id" value="${excelTemplate.id}">
        <input type="hidden" id="content" name="content" >
        <div class="layui-row">
            <div class="layui-col-md4"></div>
            <div class="layui-col-md4"></div>
            <div class="layui-col-md4">
                <button type="button" onclick="saveExcelTemplate(false);" class="layui-btn layui-btn-normal " style="position: relative;left: 40px">保存</button>
                <button type="button" onclick="submitExcelTemplate();" class="layui-btn " style="position: relative;left: 40px">提交</button>
            </div>
        </div>
    </form>
</div>
<script type="text/javascript">
    var content ='${excelTemplate.content}'
    //实例化编辑器
    //建议使用工厂方法getEditor创建和引用编辑器实例，如果在某个闭包下引用该编辑器，直接调用UE.getEditor('editor')就能拿到相关的实例
    var ue = UE.getEditor('editor');
    var layer ="";
    $(function () {
        layui.use(['layer', 'form'], function(){
            layer = layui.layer
        });
        ue.ready( function( editor ) {
            initContent();
        } );
    });

    /**
     * 自定义标签（委托单）
     */
    UE.commands['ordersbtn'] = {
        execCommand : function(cmdName){
            $.x_admin_Confirmation_Box_Show('分配委托单位', '${ctxPath}/excelTemplate/getOrders', '800', '450',function (index,layero) {
                var checkedIds = layero.find("iframe")[0].contentWindow.document.getElementById("checkedIds").value;
                var checkedNames = layero.find("iframe")[0].contentWindow.document.getElementById("checkedNames").value;
                if(checkedIds){
                    checkedNames = checkedNames.substr(0,checkedNames.length-1);
                    UE.getEditor('editor').execCommand('insertHtml', checkedNames);
                    layer.close(index);
                }else {
                    $.msg('请选择要加的委托单位', function () {
                    }, 2);
                    return false;
                }
            });
        }
    };
    //创建编辑器
    function createEditor() {
        enableBtn();
        UE.getEditor('editor');
    }
    function initContent() {
        if(content){
            UE.getEditor('editor').execCommand('insertHtml', content)
        }
    }
    function saveExcelTemplate(toList) {
        var arr = [];
        arr.push(UE.getEditor('editor').getContent());
        $('#content').val(arr.join("\n"));
        $.cajax('${ctxPath}/ajax/excelTemplate/save', $('#excelTemplate-date').serialize(), function (r) {
            var code = r.code;
            var msg = r.msg;
            if (code == '1') {
                $.msg(msg, function () {
                    if(toList){
                        window.location.href = '${ctxPath}/excelTemplate/list';
                    }
                }, code);
            } else {
                $.msg(msg, function () {
                }, 2);
            }
        });
    }
    function submitExcelTemplate() {
        saveExcelTemplate(true);
    }
</script>
<@>}